import RenderUtils from "../RenderUtils";
import {FormItemConfig, RenderTypeItem} from "../ConfigType";
import {CreateElement} from "vue/types/vue";
import {DynamicForm} from "../index.vue.d";

const input: RenderTypeItem = {
  slotNames: ['prefix', 'suffix', 'prepend', 'append'],
  name: 'input',
  /**
   *
   * @param createElement
   * @param vm
   * @param formItem
   * @return {VNode[]}
   */
  render(createElement: CreateElement, vm: DynamicForm, formItem: FormItemConfig) {
    const config = RenderUtils.getConfig(vm, formItem, {
      attrs: {
        placeholder: formItem.props?.placeholder || '请输入' + formItem.label,
      },
    }, this)
    const children = RenderUtils.renderSlotsChildren(formItem, createElement, this.slotNames, vm)
    return [
      createElement(`el-input`, config, children)
    ]
  },
  getTitle(vm, formItem) {
    // @ts-ignore
    return vm.formData[formItem.prop]
  }
}

export default input
